import React from 'react'
import {connect} from 'dva'
import {Input, Button} from 'antd'
import styles from './index.less'

@connect(({login}) => ({
  login
}))

export default class UserLogin extends React.Component {
  onChange(type, value) {
    let payload = {};
    payload[type] = value.target.value;
    this.props.dispatch({
      type: 'login/overrideStateProps',
      payload
    })
  };

  login() {
    this.props.dispatch({
      type: 'login/login',
    })
  };

  register() {
    this.props.dispatch({
      type: 'login/register',
    })
  };

  render() {
    const {login} = this.props;
    const {username, password} = login;
    return (
      <div className={styles.main}>
        账号 <Input onChange={this.onChange.bind(this, 'username')}
                        value={username}/>
        密码 <Input.Password onChange={this.onChange.bind(this, 'password')}
                                 value={password}/>
        <Button className={`${styles.other}`} onClick={this.login.bind(this)}>登录</Button>
        <Button className={styles.other} onClick={this.register.bind(this)}>注册</Button>
      </div>
    )
  }
}




